function match = findMatch(features, pos, matchfunc, varargin)
if nargin < 3
    matchfunc = @matchValue;
end
if ~isa(matchfunc, 'function_handle')
    error('MATCHFUNC must be a handler function.');
end
num = length(features);
clear match;
count = 0;
for i = 2:num
    for j = 1:i-1
        if matchfunc(features{i}, pos{i}, features{j}, pos{j}, varargin)
            count = count + 1;
            match{count} = [i, j];
        end
    end
end
end

function crit = matchValue(f1, p1, f2, p2, args)
    crit = (norm((f1 - f2) / 255) <= 0.034) ... % norm([5 5 5]/255, 2)
        && (norm((f1 - f2) / 255, 1) < 0.059) ...; % norm([5 5 5]/255, 1) 
        && (norm(p1 - p2, 2) > 64); % enough distance
end
